package com.tfjybj.itoo.exam.provider.controller;

import org.apache.dubbo.config.annotation.Reference;;
import com.dmsdbj.itoo.tool.business.ItooResult;
import com.github.pagehelper.PageInfo;
import com.tfjybj.itoo.exam.model.StudentTeachClassModel;
import com.tfjybj.itoo.exam.provider.service.StudentTeachClassService;
import com.tfjybj.itoo.teach.FacadeApi.StudentTeachClassApi;
import com.tfjybj.itoo.teach.entity.StudentTeachClassEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * StudentTeachClassController
 * studentTeachClass表
 *
 * @author 郭满亮
 * @version 2.0.0
 * @since 2.0.0 2019-01-29 15:52:00
 */
@Api(tags = {"studentTeachClass表接口"})
@RequestMapping(value = "/studentTeachClass")
@RestController
public class StudentTeachClassController {

    @Resource
    private StudentTeachClassService studentTeachClassService;

    //贾建清 2019年5月30日20:42:00
    @Reference(check = false)
    private StudentTeachClassApi studentTeachClassApi;

    //region 模板生成：基本增删改

    /**
     * 添加
     *
     * @param model StudentTeachClassModel
     * @return 添加的结果
     * @author 郭满亮
     * @since 2.0.0 2019-01-29 15:52:00
     */
    @ApiOperation(value = "添加")
    @PostMapping(value = {"/create"})
    public ItooResult create(@RequestBody StudentTeachClassModel model) {
		if (StringUtils.isEmpty(model.getStudentId())){
            return ItooResult.build(ItooResult.FAIL, "studentId为空");
        }
		if (StringUtils.isEmpty(model.getTeachClassId())){
            return ItooResult.build(ItooResult.FAIL, "teachClassId为空");
        }
        com.tfjybj.itoo.teach.entity.StudentTeachClassEntity studentTeachClassEntity = new com.tfjybj.itoo.teach.entity.StudentTeachClassEntity();
        BeanUtils.copyProperties(model, studentTeachClassEntity);
        studentTeachClassApi.save(studentTeachClassEntity);
        return ItooResult.build(ItooResult.SUCCESS, "添加成功");
    }

    /**
     * 删除
     *
     * @param id 主键id
     * @return ItooResult 是否删除成功          
     * @author 郭满亮
     * @since 2.0.0 2019-01-29 15:52:00
     */
    @ApiOperation(value = "根据id删除（单个）")
    @DeleteMapping(value = {"/delete/{id}"})
    public ItooResult delete(@ApiParam(value = "主键id", required = true) @PathVariable String id) {
        studentTeachClassApi.removeById(id);
        return ItooResult.build(ItooResult.SUCCESS, "删除成功");
    }

    /**
     * 批量删除
     *
     * @param ids ids
     * @return ItooResult 批量删除是否成功结果
     * @author 郭满亮
     * @since 2.0.0 2019-01-29 15:52:00
     */
    @ApiOperation(value = "根据id批量删除")
    @DeleteMapping(value = {"/deleteByIds"})
    @ApiImplicitParam(name = "ids", value = "ids", dataType = "List<String>", required = true)
    public ItooResult deleteByIds(@RequestBody List<String> ids) {
        studentTeachClassApi.removeByIds(ids);
        return ItooResult.build(ItooResult.SUCCESS, "批量删除成功");
    }

    /**
     * 修改
     *
     * @param model StudentTeachClassModel
     * @return 修改后的结果
     * @author 郭满亮
     * @since 2.0.0 2019-01-29 15:52:00
     */
    @ApiOperation(value = "根据id修改studentTeachClass")
    @PutMapping(value = {"/modify"})
    public ItooResult modify(@RequestBody StudentTeachClassModel model) {
		if (StringUtils.isEmpty(model.getStudentId())){
            return ItooResult.build(ItooResult.FAIL, "studentId为空");
        }
		if (StringUtils.isEmpty(model.getTeachClassId())){
            return ItooResult.build(ItooResult.FAIL, "teachClassId为空");
        }
        com.tfjybj.itoo.teach.entity.StudentTeachClassEntity studentTeachClassEntity = new com.tfjybj.itoo.teach.entity.StudentTeachClassEntity();
        BeanUtils.copyProperties(model, studentTeachClassEntity);
        studentTeachClassApi.updateById(studentTeachClassEntity);
        return ItooResult.build(ItooResult.SUCCESS, "修改成功");
    }

    /**
     * 根据id查找StudentTeachClass
     *
     * @param id 主键id
     * @return 根据id查找的结果
     * @author 郭满亮
     * @since 2.0.0 2019-01-29 15:52:00
     */
    @ApiOperation(value = "根据id查询")
    @GetMapping(value = {"/findById/{id}"})
    public ItooResult findById(@ApiParam(value = "主键id", required = true) @PathVariable String id) {
        com.tfjybj.itoo.teach.entity.StudentTeachClassEntity studentTeachClassEntity = studentTeachClassApi.getById(id);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", studentTeachClassEntity);
    }

    /**
     * 分页查询所有StudentTeachClass
     *
     * @param pageNo   页码
     * @param pageSize 每页条数
     * @return 分页查询的结果
     * @author 郭满亮
     * @since 2.0.0 2019-01-29 15:52:00
     */
    @ApiOperation(value = "分页查询所有StudentTeachClass")
    @GetMapping(value = {"/queryPageAll/{pageNo}/{pageSize}"})
    public ItooResult queryPageAll(@ApiParam(name = "pageNo",value = "页码",required = true,example = "1")@PathVariable Integer pageNo,
								   @ApiParam(name = "pageSize",value = "页数",required = true,example = "10")@PathVariable Integer pageSize) {
        PageInfo<StudentTeachClassEntity> studentTeachClasss = studentTeachClassApi.queryPageAll(pageNo, pageSize);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", studentTeachClasss);
    }
	
    //endregion

    /* **********************************以下为非模板生成的内容********************************* */

    /**
     * 根据teachClassId和templateId发布小练
     *
     * @param examName 考试名称
     * @param teachClassId 上课班Id
     * @param templateId 模板Id
     * @return 根据考试名称和上课班id以及模板id发布小练的结果
     * @author 郭满亮
     * @since 2.0.0 2019-01-29 15:52:00
     */
    @ApiOperation(value = "根据考试名称和上课班id以及模板id发布小练的结果")
    @PostMapping(value = {"/savePractice/{examName}/{teachClassId}/{templateId}"})
    public ItooResult savePractice(@ApiParam(value = "考试名称", required = true) @PathVariable String examName,
                                @ApiParam(value = "上课班Id", required = true) @PathVariable String teachClassId,
                                @ApiParam(value = "模板Id", required = true) @PathVariable String templateId) {
        return studentTeachClassService.savePractice(examName, teachClassId, templateId);
    }

    /**
     * 给上课班添加学生
     *
     * @param studentCode 学生学号
     * @param teachClassId 上课班Id
     * @param operator 操作员
     * @return 添加结果
     * @author 郭满亮
     * @since  2019年2月28日10:12:07
     */
    @ApiOperation(value = "给上课班添加学生")
    @PostMapping(value = {"/createStudent/{studentCode}/{teachClassId}/{operator}"})
    public ItooResult createStudent(@ApiParam(value = "学生学号", required = true) @PathVariable String studentCode,
                                    @ApiParam(value = "上课班Id", required = true) @PathVariable String teachClassId,
                                    @ApiParam(value = "操作员", required = true) @PathVariable String operator) {
        return studentTeachClassService.createStudent(studentCode,teachClassId,operator);
    }

    /**
     * 从上课班删除学生
     *
     * @param studentId 学生id
     * @param teachClassId 上课班Id
     * @return 删除结果
     */
    @ApiOperation(value = "从上课班删除学生")
    @DeleteMapping(value = {"/updataTeachClassStudent/{studentId}/{teachClassId}"})
    public ItooResult updataTeachClassStudent(@ApiParam(value = "学生id", required = true) @PathVariable String studentId,
                                              @ApiParam(value = "上课班Id", required = true) @PathVariable String teachClassId) {
        return studentTeachClassService.updataTeachClassStudent(studentId,teachClassId);
    }
}
